package com.zigong.app.ui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.zigong.app.base.BaseFragment;
import com.zigong.app.beans.LiveDynamic;
import com.zigong.app.ui.util.IListShowData;

import java.util.List;

/**
 * Created by rh008 on 2017/7/19.
 * 直播子模块的基类（直播间、聊天室继承）
 */

public class LivingChildFragment<T> extends BaseFragment {

    public static final int MODE_NORMAL = 0;
    public static final int MODE_SET = -1;
    public static final int MODE_SET_POS = -2;
    public static final int MODE_ADD = -3;
    public static final int MODE_ADD_POS = -4;
    public static final int MODE_PLAY = -5;

    protected OnNetCallback netCallback;

    protected String baseLiveId;

    /**
     * 是否正在直播
     */
    protected boolean isLiving;

    protected boolean hasCreated;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnNetCallback) {
            netCallback = (OnNetCallback) context;
        }
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        hasCreated = true;
    }

    @Override
    public void onDestroyView() {
        hasCreated = false;
        super.onDestroyView();
    }

    @Override
    public void onDetach() {
        if (netCallback instanceof Context) {
            netCallback = null;
        }
        super.onDetach();
    }

    /**
     * 设置数据，也可用于添加数据
     *
     * @param t    要设置的数据
     * @param mode 设置模式
     */
    public void addData(T t, int mode) {
    }

    /**
     * 添加数据，也可用于设置数据
     *
     * @param list 要添加的数据
     * @param mode 添加模式
     */
    public void addDatas(List<T> list, int mode) {
    }

    /**
     * 设置单条数据，页可用于添加单条数据
     *
     * @param data 单条数据
     * @param mode 模式
     * @param pos  位置
     */
    public void setData(T data, int mode, int pos) {
    }

    public void onRefresh() {
    }

    public void setBaseLiveId(String baseLiveId) {
        this.baseLiveId = baseLiveId;
    }

    public void setLiving(boolean living) {
        isLiving = living;
    }

    public void setNetCallback(OnNetCallback netCallback) {
        this.netCallback = netCallback;
    }

    public interface OnNetCallback {
        void onNetPrepare(LivingChildFragment fragment, int mode);

        void onNetEnd(LivingChildFragment fragment, int mode, boolean canLoadMore);

        void doOther(LivingChildFragment fragment, int mode, Object obj,Object obj2);
        void onRecylerScroll(int dx, int dy);
    }
}
